//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//
//	File		 :	PerlUtil.h
//	Contents	 :	Header file for functions emulating perl utility
//	Creation Date:	25/01/2000
//	Last Modified:	25/01/2000	lg
//	tabs width	 :	every 4 characters
//
//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#if !defined(PERL_H)
#define PERL_H

#include <vector>
#include <string>

	std::vector<std::string>&
PerlSplit (const char*& text, std::string delimiters, std::vector<std::string>& ret);

	std::string
PerlJoin (const std::vector<std::string>& strs, const std::string& link, unsigned beg = 0);

	std::vector<std::string>&
PerlSplit (	const std::string& str,
			const std::string& delimiters,
			std::vector<std::string>& ret,
			bool ignoreEmpty = true,
			unsigned max_cnt = 1000);

	std::vector<std::pair<std::string::iterator, std::string::iterator> >&	
PerlSplit (	const std::string::iterator&								str_beg,
			const std::string::iterator&								str_end,
			const std::string&											delimiters,
			std::vector<std::pair<	std::string::iterator,
									std::string::iterator> >& 			ret,
			bool														ignoreEmpty,
			unsigned													max_cnt = 1000);


	std::vector<std::string>&
PerlSplit (const char*& text, std::string delimiters, std::vector<std::string>& ret);

	std::string
PerlStrip(std::string s);

	template <typename T_container, typename T_outstream>
	T_outstream&
perl_print (T_outstream& os, const T_container& c, const std::string& sep)
{
	// nothing to print
	if (!c.size())
		return os;
	
	// print first element
	typename T_container::const_iterator i = c.begin();
	os << *i;
	
	if (c.size() == 1)
		return os;
	
	// print each successive element preceded by the seperator
	while (++i != c.end())
		os << sep << *i;
	
	return os;
}


#endif	//PERL_H
